import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class MySvg extends StatelessWidget {
  final String url;
  final String? package;
  final double? width;
  final double? height;
  final BoxFit? fit;
  final Color? color;
  final bool network;
  final bool detectUrl;

  const MySvg(this.url,
      {Key? key,
      this.width,
      this.height,
      this.fit,
      this.color,
      this.network = false,
      this.detectUrl = false,
      this.package})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool _network = network;
    if (detectUrl) {
      _network = url.startsWith("http");
    }

    if (_network) {
      return SvgPicture.network(
        url,
        width: width,
        height: height,
        fit: fit ?? BoxFit.contain,
        colorFilter:
            color != null ? ColorFilter.mode(color!, BlendMode.srcIn) : null,
      );
    }
    return SvgPicture.asset(
      url,
      package: package,
      width: width,
      height: height,
      fit: fit ?? BoxFit.contain,
      colorFilter:
          color != null ? ColorFilter.mode(color!, BlendMode.srcIn) : null,
    );
  }
}
